package com.leyou.trade.web;

import com.leyou.trade.dto.PayResultDTO;
import com.leyou.trade.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;


    @GetMapping("/url/{id}")
    public ResponseEntity<String> createPayUrl(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.payService.createPayUrl(id));

    }

    @PostMapping(value = "/wx/notify",produces = "application/xml")
    public ResponseEntity<PayResultDTO> handlerNotify(
            @RequestBody Map<String, String> notifyParm) {

        this.payService.handlerNotify(notifyParm);

        HashMap<String, String> resultMap = new HashMap<>();
        resultMap.put("return_code", "SUCCESS");
        resultMap.put("return_msg", "OK");
        return ResponseEntity.ok(new PayResultDTO());
    }


}
